/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Desarrollo.Soft.Hibernate.Control.Consultas;

import Desarrollo.Soft.Hibernate.Data.Entity.Tblalmacen;
import Desarrollo.Soft.Hibernate.Data.Entity.Tblventa;
import Desarrollo.Soft.Hibernate.Util.HibernateUtil;
import java.util.List;
import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Projections;
import org.hibernate.criterion.Property;
import org.hibernate.criterion.Restrictions;

/**
 *
 * @author r0ck3r
 */
public class ctrlConsultasVentaProducto {
    
    private static Session sessionHibernate;
    public static List<Tblalmacen> selectTblalmacenbyNombreProduct(String _producto)
    {
        try {
             try {            
            sessionHibernate  = HibernateUtil.getSessionFactory().getCurrentSession();
            sessionHibernate.beginTransaction();
            Criteria criterio =  sessionHibernate.createCriteria(Tblalmacen.class);  
            criterio.createAlias("catproductos", "catpro");
            criterio.add(Restrictions.like("catpro.valor", _producto+"%"));
            
            return criterio.list();
        } catch (Exception e) {
            throw e;
        }finally
        {
             System.gc();
        }
        } catch (Exception e) {
            throw  e;
        }
    }
    
    public static  Tblventa createItem(Tblventa _entity, Class type)
    {
        try {
            sessionHibernate = HibernateUtil.getSessionFactory().getCurrentSession();
            sessionHibernate.beginTransaction();
            sessionHibernate.save(_entity);
            sessionHibernate.getTransaction().commit();
            
            return _entity;
        } catch (Exception e) {
            throw e;
        }finally
        {            
            System.gc();
        }
    }
}
